aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/routes/bots/[bot_name]/matches.svelte
blob: 979054c4d6b77026924fe5f6087d125f7c5acb23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script lang="ts" context="module">
  import { ApiClient } from "$lib/api_client";

  export async function load({ params, fetch }) {
    try {
      const apiClient = new ApiClient(fetch);
      const botName = params["bot_name"];

      const [allBots, allMaps] = await Promise.all([
        apiClient.get("/api/bots"),
        apiClient.get("/api/maps"),
      ]);

      return {
        props: {
          botName,
          allBots,
          allMaps,
        },
      };
    } catch (error) {
      return {
        status: error.status,
        error: new Error("failed to load matches"),
      };
    }
  }
</script>

<script lang="ts">
  import BotMatchList from "$lib/components/matches/BotMatchList.svelte";
  import Select from "svelte-select";

  export let botName: string;
  export let allBots: object[];
  export let allMaps: object[];

  let opponentName: string | undefined;
  let mapName: string | undefined;
</script>

<div class="container">
  <div class="selections">
    <Select
      items={allBots}
      placeholder="Select opponent"
      label="name"
      itemId="name"
      bind:justValue={opponentName}
    />
    <Select
      items={allMaps}
      placeholder="Select map"
      label="name"
      itemId="name"
      bind:justValue={mapName}
    />
  </div>
  <BotMatchList {botName} {opponentName} {mapName} />
</div>

<style lang="scss">
  .container {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
  }

  .selections {
    display: flex;
    padding: 16px 4px;
  }
</style>